<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/13
 * Time: 15:25
 */

/**
 * 连接数组 转换为字符串
 * @param array $array | 要连接的数组
 * @param string $joiner | key value 连接符
 * @param string $connect | 间隔符
 * @param array $prefix | 前缀
 * @return string
 */
function spliceWhereArray(array $array, $prefix = [], $joiner = ' ', $connect = ',')
{
    if (empty($array)) {
        return '';
    }
    $str = '';
    foreach ($array as $k => $v) {
        $str = $str . ' ' . $prefix[$k] . '.' . $k . $joiner . $v . ' ' . $connect;
    }
    $str = rtrim($str, $connect);
    return $str;
}

echo spliceWhereArray(['city_id' => 1,  'industry_id' => 3], ['city_id'=>'b','province_id'=> 'c', 'industry_id'=> 'd'], '=', 'and');